package com.ruoyi.web.controller.memberManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PointsResetRule;
import com.ruoyi.system.service.IPointsResetRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分清零规则设置（存储会员积分清零的规则配置）Controller
 *
 * @author ruoyi
 * @date 2025-05-20
 */
@Api(tags="积分清零规则设置")
@RestController
@RequestMapping("/system/pointsResetRule")
public class PointsResetRuleController extends BaseController
{
    @Autowired
    private IPointsResetRuleService pointsResetRuleService;

    /**
     * 查询积分清零规则设置列表
     */
    @ApiOperation("查询积分清零规则设置列表")
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PointsResetRule pointsResetRule)
    {
        startPage();
        List<PointsResetRule> list = pointsResetRuleService.selectPointsResetRuleList(pointsResetRule);
        return getDataTable(list);
    }

    /**
     * 导出积分清零规则设置列表
     */
    @ApiOperation("导出积分清零规则设置列表")
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "积分清零规则设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsResetRule pointsResetRule)
    {
        List<PointsResetRule> list = pointsResetRuleService.selectPointsResetRuleList(pointsResetRule);
        ExcelUtil<PointsResetRule> util = new ExcelUtil<PointsResetRule>(PointsResetRule.class);
        util.exportExcel(response, list, "积分清零规则设置数据");
    }

    /**
     * 通过id获取积分清零规则设置详细信息
     */
    @ApiOperation("通过id获取积分清零规则设置详细信息")
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointsResetRuleService.selectPointsResetRuleById(id));
    }

    /**
     * 新增积分清零规则设置
     */
    @ApiOperation("新增积分清零规则设置")
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "积分清零规则设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsResetRule pointsResetRule)
    {
        return toAjax(pointsResetRuleService.insertPointsResetRule(pointsResetRule));
    }

    /**
     * 修改积分清零规则设置
     */
    @ApiOperation("修改积分清零规则设置")
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "积分清零规则设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsResetRule pointsResetRule)
    {
        return toAjax(pointsResetRuleService.updatePointsResetRule(pointsResetRule));
    }

    /**
     * 通过id批量删除积分清零规则设置信息
     */
    @ApiOperation("通过id批量删除积分清零规则设置信息")
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "积分清零规则设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsResetRuleService.deletePointsResetRuleByIds(ids));
    }
}
